import { readFileSync } from 'fs';
import * as yaml from 'js-yaml';
import { join } from 'path';

const configFileNameObj = {
  development: 'dev',
  test: 'test',
  production: 'prod',
};

const env = process.env.NODE_ENV || 'development';
const configFile = configFileNameObj[env];

if (!configFile) {
  throw new Error(`未找到对应的配置文件映射，NODE_ENV=${env}`);
}

export default () => {
  const configPath = join(__dirname, `./${configFile}.yml`);
  return yaml.load(readFileSync(configPath, 'utf8')) as Record<string, any>;
};
